<template>
	<box interactive="true">
		<img src="res/ui/fightBg.png" width="800" height="600"></img>
		<box x="180" y="180" color="#ffCEFA" note="上色">
			<ani @bind="heNode" src="res/ani/3/man_0_3.json" loop="true" speed="6" @click="attack()"></ani>
			<txt text="点我啊" y="15" size="14" color="#ffffff"></txt>
		</box>
		<ani :src="my.src" loop="true" speed="6" :x="my.x" :y="my.y"></ani>
		<img src="res/ui/buttonLN.png" width="100" height="50" x="-120" y="-70" @click="close()">
			<txt text="返回" x="20" y="10" size="14" color="#ffffff"></txt>
		</img>
	</box>
</template>

<script>
init(){
	this.my= {
		src: "res/ani/3/man_0_7.json",
		x: 650,
		y: 350,
		status: 0,
		attacking: 0
	};
	this.heNode= null;
	this.attackTime= 0;
}

create() {
	console.log("fight create");
	PLAYER.visible = false;
	UI.visible = false;
}

update(delta) {
	this.runToAttack(delta);
}

destroyed() {
	
}

close() {
	PLAYER.visible = true;
	UI.visible = true;
	this.closeTpl();//场景销毁用这个,  只是隐藏用 this.visible = false;
}

attack(){
	console.log("attack");
	this.upMyStatus(2);
	this.my.attacking = 1;
}

runToAttack(delta){
	if(this.my.attacking == 1){
		if(this.my.x > 220 || this.my.y > 210){
			this.my.x -= (650-220)/80;
			this.my.y -= (350-210)/80;
		}else{
			this.my.attacking = 2;
			this.upMyStatus(3);
			this.attackTime = 0;
		}
	}else if(this.my.attacking == 2){
		if(this.attackTime == 80){
			this.my.attacking = 3;
			this.upMyStatus(1);
		}
		this.attackTime++;
	}else if(this.my.attacking == 3){
		if(this.my.x < 650 || this.my.y < 350){
			this.my.x += (650-220)/60;
			this.my.y += (350-210)/60;
		}else{
			this.my.attacking = 0;
			this.upMyStatus(0);
		}
	}
}

upMyStatus(status){
	this.my.status = status;
	this.my.src = "res/ani/3/man_" + this.my.status + "_7.json";
}
</script>